/* $RCSFile: ModulesLayout.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.Core/Design/ModulesLayout.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:28  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;
using System.Globalization;

using AddonNice.Diagnostics;
using AddonNice.Configuration;

namespace AddonNice.Design
{
	/// <summary>
	/// The ModulesLayout class encapsulates all the settings
	/// of the currently selected theme
	/// </summary>
	public class ModulesLayout
	{
        #region Private Declarations
        
        Hashtable    _ThemeParts    =   new Hashtable();
        string _minimize_color      =   string.Empty;
        string _name;
        string _webPath;
        #endregion

        public Hashtable ThemeParts
        {
            get
            {
                return _ThemeParts;
            }
        }



        public LiteralControl GetLiteralControl(string name)
        {
            return new LiteralControl(GetThemePart(name));
        }

        public string GetThemePart(string name)
        {

            if (_ThemeParts.ContainsKey(name))
            {
                ModulesLayoutPart part = (ModulesLayoutPart)_ThemeParts[name];
                if ( ModulesLayoutTrace.Sw.TraceVerbose )
                    Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ModulesLayout GetThemePart name: {0}, ModulesLayoutPart: {1}", name, part.Html),ModulesLayoutTrace.Sw.Info);
                return part.Html;
            }
            return string.Empty;
        }


        /// <summary>
        /// The ModulesLayout minimize color 
        /// </summary>
        public string MinimizeColor
        {
            get
            {
                return _minimize_color;
            }
            set
            {
                _minimize_color = value;
            }
        } 

        /// <summary>
        /// The ModulesLayout Name (must be the directory in which is located)
        /// </summary>
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }

        /// <summary>
        /// Current Physical Path. Readonly.
        /// </summary>
        public string Path
        {
            get
            {
                return HttpContext.Current.Server.MapPath(WebPath);
            }
        }

        /// <summary>
        /// Get the ModulesLayout physical file name.
        /// Set at runtime using Physical Path. NonSerialized.
        /// </summary>
        public string ModulesLayoutFileName
        {
            get
            {

                if (WebPath == string.Empty)
                {
                    string msg  =   string.Format("[E]ModulesLayout ModulesLayoutFileName WebPath empty name: {0}", Name);
                    if ( ModulesLayoutTrace.Sw.TraceError )
                        Trace.WriteLine(msg,ModulesLayoutTrace.Sw.Info);
                    throw new ArgumentNullException("WebPath", msg);
                }
                //Try to get current theme from public folder
                return System.IO.Path.Combine(Path,StStr.ModulesLayoutFileName);
            }
        }

        /// <summary>
        /// Current Web Path.
        /// It is set at runtime and therefore is not serialized
        /// </summary>
        public string WebPath
        {
            get
            {
                return _webPath;
            }
            set
            {
                if ( ModulesLayoutTrace.Sw.TraceVerbose )
                    Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ModulesLayout WebPath Set name: {0}, value: {1}", Name, value),ModulesLayoutTrace.Sw.Info);
                _webPath = value;
            }
        }
    }
}